Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publicize: Move the publicize-connections endpoint to the package #40637

Closed
wants to merge 11 commits into from

Conversation

pablinos
Copy link
Contributor

This is following on from various discussions we've been having about how to refactor the API endpoints for connections management. This is a variation on the approach in #40607 but repurposes the existing endpoint rather than creating a new backwards compatible one.

Fixes #

Proposed changes:

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Go to '..'

This is following on from various discussions we've been having about
how to refactor the API endpoints for connections management. This is a
variation on the approach in #40607 but repurposes the existing endpoint
rather than creating a new backwards compatible one.
Copy link
Contributor

github-actions bot commented Dec 16, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the try/move-publicize-connections-endpoint branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack try/move-publicize-connections-endpoint
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Feature] Publicize Now Jetpack Social, auto-sharing [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Dec 16, 2024
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for January 7, 2025 (scheduled code freeze on undefined).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have gone back and forth too many times and I don't think we should continue doing that. Let us get this PR in its final shape addressing the comments I added.

I am not sure about your approach about the endpoint initialization on WPCOM, so I will wait for your thoughts on that.

@pablinos pablinos changed the title Publicize: Mave the publicize-connections endpoint to the package Publicize: Move the publicize-connections endpoint to the package Dec 17, 2024
Copy link
Contributor Author

@pablinos pablinos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has turned into a bit of a monster, which is a shame. I was hoping we could do this with smaller changes. It's also almost the same as #40607, but I suppose that means we've converged on a solution.

@@ -0,0 +1,431 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annoying thing about this change is that this file is now so different from the publicize-connections.php file it replaces, it's now a new file, rather than the diff showing that it's moved. Overall it is using the same code and method names.

* @return array Connection objects in the same shape as from `get_connections`
*/
public static function get_connections_data( $run_tests = false ) {
// TODO decide on caching
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we should use a transient like we do in Publicize?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caching should ideally happen outside of the controller. We can deal with it later.

$response = Client::wpcom_json_api_request_as_user( sprintf( $path, $site_id ), 'v2', array( 'method' => 'GET' ) );

if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
// TODO log error.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to work out what's best to do here. I feel like we should return an error. If it's empty like this then everything will still function but will be blank. How do we get an error message to the user? Maybe it's ok for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always return an array here and pass the error in some other way like JITM.

@pablinos pablinos marked this pull request as ready for review December 17, 2024 20:31
@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Dec 17, 2024
Comment on lines -592 to +593
$cmeta = $this->get_connection_meta( $connection );
$cmeta = $this->get_connection_meta( $connection );
$username = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since username field is deprecated in favour of external_handle, we don't need to update it. We are going to remove it anyway in the future.

@manzoorwanijk
Copy link
Member

It's funny that this PR now has more changes (+473 −307) than #40607 (+459 −31) which it tried not to do 😄

),
);

$test_fields = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please avoid adding these test fields here? We no longer use them. The only field that we need here is the status field.

We can move this schema back to connection test results endpoint and remove it in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need more than the status field, or we need to make sure the status field can also be must_reauth for LinkedIn. I think that flow does use some of these other fields too, but it needs some work anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our new connections management uses only the status field, nothing else.

Comment on lines +293 to +299
'test_success' => 'connectionTestPassed',
'test_message' => 'connectionTestMessage',
'error_code' => 'connectionTestErrorCode',
'can_refresh' => 'userCanRefresh',
'refresh_text' => 'refreshText',
'refresh_url' => 'refreshURL',
'connection_id' => 'connectionID',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like these unused fields in this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, we can move them back to the subclass.

*
* @return true|WP_Error
*/
public function get_items_permission_check() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This callback in the future can be moved to a base class to share between different publicize controllers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was trying to avoid introducing a base class at this stage. I was also trying to make the change a move of the endpoint, but we end up having to make so many other changes to the class, it ends up getting treated as a new file

array(
'connection_id' => $connection_id,
'display_name' => $publicize->get_display_name( $service_name, $connection ),
'external_handle' => $username,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

external_handle handle is not actually the username. It's a little different. With this PR, I get this, which is incorrect:

Screenshot 2024-12-18 at 9 31 15 AM

You can see the get_external_handle method I added in #40607

Copy link
Contributor Author

@pablinos pablinos Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't have it for Facebook pages for example. We can surely improve on that to ensure that our keyring service has all that information.

Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from many other issues that I pointed out

  • The initialization on Simple sites is yet to be taken care of
  • The shape of the data is incorrect. It should be an array of connections, not an array of REST responses.
image

@pablinos
Copy link
Contributor Author

  • The initialization on Simple sites is yet to be taken care of

That is taken care of in the accompanying WPCOM PR

  • The shape of the data is incorrect. It should be an array of connections, not an array of REST responses.

Yes, we should fix that. It was introduced from trying to make Phan happy. I'm not sure we should be using the prepare_item_for_response method

@pablinos
Copy link
Contributor Author

Closing in favour of #40607

@pablinos pablinos closed this Dec 18, 2024
@github-actions github-actions bot removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Status] Needs Team Review labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Publicize Now Jetpack Social, auto-sharing [Package] Publicize [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants